/*
 * Created on Feb 15, 2007
 */
package sandboxmv.entities;

import ecologylab.game2d.common.CompressedVector;
import ecologylab.game2d.entity.Mover;
import ecologylab.xml.library.geom.Vector2d;

/**
 * @author Zach Toups (toupsz@gmail.com)
 */
public class Hero extends Mover implements HeroConstants
{
    @xml_attribute double           jumpAbil    = START_JUMP_ABIL;

    @xml_attribute CompressedVector aimDir      = new CompressedVector(1.0, 0.0);

    @xml_attribute String           roomUID;

    private CompressedVector        intendedVel = new CompressedVector(0, 0);

    /**
     * @return the roomUID
     */
    public String getRoomUID()
    {
        return roomUID;
    }

    /**
     * 
     */
    public Hero()
    {
        super();
    }

    /**
     * @param x
     * @param y
     * @param dir
     * @param speed
     * @param idt
     *            won
     * @param inGameOrder
     */
    public Hero(double x, double y, int speed, String id, int inGameOrder,
            String startingRoom)
    {
        super(x, y, new CompressedVector(0, -1), speed, id, inGameOrder);

        this.roomUID = startingRoom;
    }

    public void setActualVelToIntended()
    {
        this.vel = intendedVel;
    }

    public void addToActualVel(CompressedVector gravity)
    {
        this.vel.add(gravity);
    }

    public void addToIntendedVel(CompressedVector gravity)
    {
        this.intendedVel.add(gravity);
    }

    public void addBackwardImpulse(double distance)
    {
        this.addForwardImpulse(-1 * distance);
    }

    /**
     * Causes the Mover to move forward at its speed.
     */
    public void addForwardImpulse()
    {
        this.addForwardImpulse(maxSpeed);
    }

    /*
     * (non-Javadoc)
     * 
     * @see rogue.entities.Mover#addLeftImpulse()
     */
    @Override public void addLeftImpulse()
    {
        this.addLeftImpulse(maxSpeed);
    }

    /*
     * (non-Javadoc)
     * 
     * @see rogue.entities.Mover#addRightImpulse()
     */
    @Override public void addRightImpulse()
    {
        this.addRightImpulse(maxSpeed);
    }

    /*
     * (non-Javadoc)
     * 
     * @see rogue.entities.Mover#addLeftImpulse(double)
     */
    @Override public void addLeftImpulse(double speed)
    {
        this.dir.rotate(-Math.PI / 2.0);
        this.intendedVel.add(CompressedVector.scalarMultiply(dir, speed
                * currentMultiplier));
        this.dir.rotate(Math.PI / 2.0);
    }

    /*
     * (non-Javadoc)
     * 
     * @see rogue.entities.Mover#addRightImpulse(double)
     */
    @Override public void addRightImpulse(double speed)
    {
        this.dir.rotate(Math.PI / 2.0);
        this.intendedVel.add(CompressedVector.scalarMultiply(dir, speed
                * currentMultiplier));
        this.dir.rotate(-Math.PI / 2.0);
    }

    /**
     * Causes the Mover to clear it's velocity vector, then sets the velocity to
     * the direction vector times speed.
     * 
     * @param speed -
     *            the distance (in game space coordinates) to attempt to move
     *            forward
     */
    public void addForwardImpulse(double speed)
    {
        this.intendedVel.add(Vector2d.scalarMultiply(dir, speed
                * currentMultiplier));
    }
    
    public void addAcc(CompressedVector newAcc)
    {
        this.acc.add(newAcc);
    }

    public void applyIntendedVel(double tS)
    {
        this.vel.add(CompressedVector.scalarMultiply(this.intendedVel, tS));
    }
    
    public void unapplyIntendedVel(double tS)
    {
        this.vel.sub(CompressedVector.scalarMultiply(this.intendedVel, tS));
    }
}
